package com.app.controller;

import com.app.model.MilitaryTrainModel;
import com.app.service.MilitaryTrainService;
import com.app.util.CommonHelp;
import com.app.util.Result;
import com.app.vo.MilitaryTrainVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * 军事训练综合评价表
 */
@Slf4j
@RestController
@Controller
@RequestMapping("/api/militaryTrain")
public class MilitaryTrainController {

    @Autowired
    private MilitaryTrainService militaryTrainService;

    //查询军事训练综合评价表
    @GetMapping("/getMilitaryTrainList")
    public Result getVillageIndustryList(@RequestParam(defaultValue = "0") Integer page,
                                         @RequestParam(defaultValue = "10") Integer limit) {
        MilitaryTrainVo militaryTrainList = militaryTrainService.getMilitaryTrainList(page, limit);
        return Result.success(militaryTrainList);
    }

    //根据id查询军事训练综合评价表
    @GetMapping("/getMilitaryTrainById")
    public Result getMilitaryTrainById(Integer id) {
        MilitaryTrainModel militaryTrainModel = militaryTrainService.getById(id);
        return Result.success(militaryTrainModel);
    }

    //新增和修改军事训练综合评价表
    @PostMapping("/addAndUpdateMilitaryTrain")
    public Result addAndUpdateMilitaryTrain(@RequestBody MilitaryTrainModel militaryTrainModel) {
        MilitaryTrainModel militaryTrain = militaryTrainService.getById(militaryTrainModel.getId());
        if (militaryTrain != null) {
            militaryTrainModel.setUpdateTime(CommonHelp.getNowTimestamp());
            militaryTrainService.updateById(militaryTrainModel);
            return Result.success("修改成功");
        } else {
            militaryTrainModel.setCreateTime(CommonHelp.getNowTimestamp());
            militaryTrainService.save(militaryTrainModel);
            return Result.success("添加成功");
        }
    }

    //删除军事训练综合评价表
    @GetMapping("/delMilitaryTrain")
    public Result delMilitaryTrain(Integer id) {
        militaryTrainService.removeById(id);
        return Result.success("删除成功");
    }

}
